package com.ruoyi.project.poem.audiospider.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.poem.audiospider.domain.AudioSpider;
import com.ruoyi.project.poem.audiospider.service.IAudioSpiderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 音频整理Controller
 * 
 * @author shixiangwen
 * @date 2021-03-03
 */
@Controller
@RequestMapping("/poem/audiospider")
public class AudioSpiderController extends BaseController
{
    private String prefix = "poem/audiospider";

    @Autowired
    private IAudioSpiderService audioSpiderService;

    @RequiresPermissions("poem:audiospider:view")
    @GetMapping()
    public String audiospider()
    {
        return prefix + "/audiospider";
    }

    /**
     * 查询音频整理列表
     */
    @RequiresPermissions("poem:audiospider:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AudioSpider audioSpider)
    {
        startPage();
        List<AudioSpider> list = audioSpiderService.selectAudioSpiderList(audioSpider);
        return getDataTable(list);
    }

    /**
     * 导出音频整理列表
     */
    @RequiresPermissions("poem:audiospider:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AudioSpider audioSpider)
    {
        List<AudioSpider> list = audioSpiderService.selectAudioSpiderList(audioSpider);
        ExcelUtil<AudioSpider> util = new ExcelUtil<AudioSpider>(AudioSpider.class);
        return util.exportExcel(list, "audiospider");
    }

    /**
     * 新增音频整理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存音频整理
     */
    @RequiresPermissions("poem:audiospider:add")
    @Log(title = "音频整理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AudioSpider audioSpider)
    {
        return toAjax(audioSpiderService.insertAudioSpider(audioSpider));
    }

    /**
     * 修改音频整理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AudioSpider audioSpider = audioSpiderService.selectAudioSpiderById(id);
        mmap.put("audioSpider", audioSpider);
        return prefix + "/edit";
    }

    /**
     * 修改保存音频整理
     */
    @RequiresPermissions("poem:audiospider:edit")
    @Log(title = "音频整理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AudioSpider audioSpider)
    {
        return toAjax(audioSpiderService.updateAudioSpider(audioSpider));
    }

    /**
     * 删除音频整理
     */
    @RequiresPermissions("poem:audiospider:remove")
    @Log(title = "音频整理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(audioSpiderService.deleteAudioSpiderByIds(ids));
    }
}
